﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace ProgNetComponents.Design.Attributes
{
    /// <summary>
    /// BrowsableByMethodAttribute 
    /// </summary>
    public class BrowsableByMethodAttribute : Attribute, IDynamicAttribute
    {
        /// <summary>
        /// Gets or sets method name
        /// </summary>
        public string IsBrowsableMethod
        {
            get;
            set;
        }
        /// <summary>
        /// Creates BrowsableByMethodAttribute instance
        /// </summary>
        /// <param name="IsBrowsableMethod"></param>
        public BrowsableByMethodAttribute(string IsBrowsableMethod)
        {
            this.IsBrowsableMethod = IsBrowsableMethod;
        }
        /// <summary>
        /// Gets BrowsableAttribute
        /// <para>browsable parameter is return by invoking IsBrowsableMethod method</para>
        /// </summary>
        /// <param name="owner"></param>
        /// <returns></returns>
        public Attribute GetRealAttribute(object owner)
        {
            bool isBrowsable = owner.RunMethod(IsBrowsableMethod).AsBool();
            return new BrowsableAttribute(isBrowsable);
        }
    }
}
